package ru.ognick.option;

import java.io.File;
import java.util.ArrayList;

import ru.ognick.logic.Training;
import ru.ognick.utils.FileManager;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

public class PraxisAdapter extends ArrayAdapter<BundleEditor> {

	private ArrayList<BundleEditor> listBundle = null;
	
	public PraxisAdapter(Context context, int textViewResourceId,
			ArrayList<BundleEditor> objects) {
		super(context, textViewResourceId, objects);
		listBundle = objects;
	}
	

	public BundleEditor getItem(int position) {
		return listBundle.get(position);
	}
	

	public View getView(int position, View convertView, ViewGroup parent) {
		return listBundle.get(position).getLayout();
	}
	
	public void save(File file) {
		Training training = new Training();
		for (BundleEditor bundle : listBundle) {
			bundle.save();
			training.add(bundle.getPraxis());
		}
		FileManager.save(file,training);
	}
}
